/******************* 公共变量 *******************/
var userId = core.getUrlData('user_id');

/******************* Vue初始化代码 *******************/
var vm = new Vue({
	el: '.wrap',
	data: {
		password: '',
		newPw: '',
		confirmPw: '',
		user_forgetpw: userForgetPwUrl + '?user_id=' + userId,
		btnJudge: true
	},
	methods: {
		checkPw: function (event) {
			var $this = $(event.target),
				thisIndex = $this.parent().index(),
				thisVal = $this.val();
			if (thisVal) {
				if (thisVal.match(/^\d{6}$/)) {
					if (thisIndex == 1) {
						if (thisVal != this.confirmPw) {
							core.layerHint('两次输入的密码不一致，请重新输入');
						}
					} else if (thisIndex == 2) {
						if (thisVal != this.newPw) {
							core.layerHint('两次输入的密码不一致，请重新输入');
						}
					}
				} else {
					core.layerHint('请输入6位纯数字密码');
				}
			} else {
				core.layerHint('输入密码不可为空');
			}
		},
		submit: function () {
			var _this = this;
			if (this.password) {
				if (this.password.match(/^\d{6}$/)) {
					if (this.newPw) {
						if (this.newPw.match(/^\d{6}$/)) {
							if (this.confirmPw) {
								if (this.newPw.match(/^\d{6}$/)) {
									if (this.newPw == this.confirmPw) {
										if (this.btnJudge) {
											this.btnJudge = false;
											$.ajax({
												url: userPwModifyUrl,
												type: 'post',
												data: {
													user_id: userId,
													password: this.password,
													password1: this.newPw,
													password2: this.confirmPw,
												},
												success: function(data) {
													console.log(data);
													setTimeout(function () {
														_this.btnJudge = true;
													}, 1000);
													if (data.result == 1) {
														core.hintBack(data.message);
													} else {
														core.layerHint(data.message);
													}
												}
											});
										}
									} else {
										core.layerHint('两次输入的密码不一致，请重新输入');
									}
								} else {
									core.layerHint('确认密码必须为6位纯数字');
								}
							} else {
								core.layerHint('确认密码不可为空');
							}
						} else {
							core.layerHint('新密码必须为6位纯数字');
						}
					} else {
						core.layerHint('新密码不可为空');
					}
				} else {
					core.layerHint('旧密码必须为6位纯数字密码');
				}
			} else {
				core.layerHint('旧密码不可为空');
			}
		}
	},
	computed: {
		
	},
	components: {
		
	},
	created: function () {
		
	},
	mounted: function () {
		common.bindBack();
	},
	updated: function () {
		
	}
});